local hx__laidaczkr = fk.CreateSkill {
  name = "hx__laidaczkr",
  tags = {Skill.Compulsory}
}

hx__laidaczkr:addEffect(fk.AfterCardsMove, {
  anim_type = "special",
  can_trigger = function(self, event, target, player)
    local room = player.room
    local num = 0
    local ret = true
    if not (player:hasSkill(hx__laidaczkr.name) and room:getTag("hx__laidaczkr_no") == nil ) then return false end
    room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function (e)
      if num >= 2 then
        ret = false
        return true
      end
      for _, move in ipairs(e.data) do
        if move.from and move.from.phase == Player.Play then
          for _, info in ipairs(move.moveInfo) do
            local card = Fk:getCardById(info.cardId)
            if info.fromArea == Card.PlayerHand and card.type == Card.TypeTrick then
              num = num + 1
              if num >= 2 then ret = true end
            end
          end
        end
      end
    end, Player.HistoryPhase)
    return num >= 2 and ret
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player)
    local room = player.room
    room:addPlayerMark(player, "@hx__laidaczkr_chengzi", 1)
    if player:getMark("@hx__laidaczkr_chengzi") >= 5 then
      room:addPlayerMark(player, "@@hx__laidaczkr_chengzi", 1)
      room:setBanner("hx__laidaczkr_no", false)
    end
  end,
})


hx__laidaczkr:addEffect(fk.AfterCardsMove, {
  anim_type = "negative",
  priority = 2,
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(hx__laidaczkr.name) or player.dead then return false end
    return not table.find(player:getCardIds("h"), function(id)
      return Fk:getCardById(id).type == Card.TypeBasic
    end) and player.room:getTag("hx__laidaczkr_no") ~= nil
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player.room:setBanner("hx__laidaczkr_no", nil)
    player.room:setPlayerMark(player, "@@hx__laidaczkr_chengzi", 0)
  end,
})

hx__laidaczkr:addEffect("viewas", {
  anim_type = "support",
  pattern = "peach",
  prompt = function (self, player)
    return "你可以将一张锦囊牌牌当作【桃】使用"
  end,
  handly_pile = true,
  card_filter = function(self, player, to_select, selected)
    return Fk:getCardById(to_select).type == Card.TypeTrick and #selected == 0
  end,
  view_as = function(self, player, cards)
    if #cards ~= 1 then return end
    local card = Fk:cloneCard("peach")
    card:addSubcard(cards[1])
    card.skillName = hx__laidaczkr.name
    return card
  end,
  enabled_at_play = function (self, player)
    return Fk:currentRoom():getBanner("hx__laidaczkr_no") ~= nil
  end,
  enabled_at_response = function (self, player)
    return Fk:currentRoom():getBanner("hx__laidaczkr_no") ~= nil
  end,
})

return hx__laidaczkr
